package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.standard.StandardNames;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.wff.WffOp.applyMode;

@SuppressWarnings("serial")
public class WffPrimCategory implements WffCond
{
  private final WffBuildOp tgt;
  private final WffOp ptn;
  private final Location loc;

  public WffPrimCategory(Location loc, WffBuildOp tgt, WffOp ptn)
  {
    this.tgt = tgt;
    this.ptn = ptn;
    this.loc = loc;
  }

  @Override
  public applyMode satisfied(IAbstract env[], Location loc, WffEngine engine)
  {
    IAbstract term = tgt.build(env, loc, engine);
    return ptn.apply(term, env, loc, engine);
  }

  public Location getLoc()
  {
    return loc;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    tgt.prettyPrint(disp);
    disp.append(" ");
    disp.append(StandardNames.WFF_DEFINES);
    disp.append(" ");
    ptn.prettyPrint(disp);
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }
}
